package com.fuhao.pay.asyntask;

import com.alibaba.fastjson.JSONObject;
import com.fuhao.pay.constant.PayConstant;
import com.fuhao.pay.constant.RabbitConstants;
import com.fuhao.pay.entity.PaymentTransactionEntity;
import com.fuhao.pay.mq.producer.IntegralProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author zhang
 * @title: 异步推送增加积分消息到MQ
 */
@Slf4j
@Component
public class IntegralMqAsynTask {

    @Autowired
    private IntegralProducer integralProducer;

    @Async
    public void addMQIntegral(PaymentTransactionEntity paymentTransaction) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("paymentId", paymentTransaction.getPaymentId());//商户支付ID
        jsonObject.put("userId", paymentTransaction.getUserId());//支付用户
        jsonObject.put("paymentChannel",paymentTransaction.getPaymentChannel());//支付渠道
        jsonObject.put("integral", 100);//增加的积分，这里暂时写死
        integralProducer.send(RabbitConstants.INTEGRAL_EXCHANGE_NAME,RabbitConstants.MQ_ROUTING_KEY_SEND_INTEGRAL,jsonObject);
    }
}
